<?php
    class Default_Model_Resort extends Zend_Db_Table_Abstract
    {
        protected $_db;

		public function __construct()
		{
			$this->_db = Zend_Registry::get('db');
		}

        public function listItem($locale)
        {
            $resort = array(
                'id',
                'star',
                'image',
                'tag_id',
            );
            $resort_language = array(
                'name',
                'address',
                'description',
            );
            $sql = $this->_db->select()
                            ->from('resort AS h', $resort)
                            ->join('resort_language AS hl', 'hl.resort_id = h.id', $resort_language)
                            ->join('language AS l', 'l.id = hl.language_id', null)
                            ->where('h.status = 1')
                            ->where('l.locale = ?', $locale)
                            ->order('h.id DESC');
            return $sql;
        }

        public function listItemByTag($tag_id, $locale)
        {
            $resort = array(
                'id',
                'star',
                'image',
                'tag_id',
            );
            $resort_language = array(
                'name',
                'address',
                'description',
            );
            $sql = $this->_db->select()
                            ->from('resort AS h', $resort)
                            ->join('resort_language AS hl', 'hl.resort_id = h.id', $resort_language)
                            ->join('language AS l', 'l.id = hl.language_id', null)
                            ->where('h.tag_id = ?', $tag_id)
                            ->where('h.status = 1')
                            ->where('l.locale = ?', $locale)
                            ->order('h.id DESC');
            return $sql;
        }

        public function listItemByArea($area_id, $locale)
        {
            $resort = array(
                'id',
                'star',
                'image',
                'tag_id',
            );
            $resort_language = array(
                'name',
                'address',
                'description',
            );
            $sql = $this->_db->select()
                            ->from('resort AS h', $resort)
                            ->join('resort_language AS hl', 'hl.resort_id = h.id', $resort_language)
                            ->join('language AS l', 'l.id = hl.language_id', null)
                            ->where('h.area_id = ?', $area_id)
                            ->where('h.status = 1')
                            ->where('l.locale = ?', $locale)
                            ->order('h.id DESC');
            return $sql;
        }

        public function listItemByLocation($location_id, $locale)
        {
            $resort = array(
                'id',
                'star',
                'image',
                'tag_id',
            );
            $resort_language = array(
                'name',
                'address',
                'description',
            );
            $sql = $this->_db->select()
                            ->from('resort AS r', $resort)
                            ->join('resort_language AS rl', 'rl.resort_id = r.id', $resort_language)
                            ->join('language AS l', 'l.id = rl.language_id', null)
                            ->where('r.location_id = ?',$location_id)
                            ->where('r.status = 1')
                            ->where('l.locale = ?', $locale)
                            ->order('r.id DESC');
            return $sql;
        }

        public function getItem($id, $locale)
        {
            $resort = array(
                'image',
                'location_id',
                'tag_id',
                'area_id',
                'star',
            );
            $resort_language = array(
                'name',
                'description',
                'address',
                'policy',
                'cozy',
                'condition',
            );
            $sql = $this->_db->select()
                            ->from('resort AS r', $resort)
                            ->join('resort_language AS rl', 'rl.resort_id = r.id', $resort_language)
                            ->join('language AS l', 'l.id = rl.language_id', null)
                            ->where('r.id = ?', $id)
                            ->where('r.status = 1')
                            ->where('l.locale = ?', $locale);
            $result = $this->_db->fetchRow($sql);
            return $result;
        }
    }
